<?php

namespace app\admin\model;

use think\Model;


class Orders extends Model
{





    // 表名
    protected $name = 'orders';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'pay_status_text',
        'delivery_status_text',
        'tableware_status_text'
    ];



    public function getStatusList()
    {
        return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '6' => __('Status 6')];
    }

    public function getPayStatusList()
    {
        return ['1' => __('Pay_status 1'), '2' => __('Pay_status 2')];
    }

    public function getDeliveryStatusList()
    {
        return ['1' => __('Delivery_status 1'), '0' => __('Delivery_status 0')];
    }

    public function getTablewareStatusList()
    {
        return ['1' => __('Tableware_status 1'), '0' => __('Tableware_status 0')];
    }

    public function getCancelReasonList(){
        $list = config('site.cancelreason')??[];
        return $list;
    }

        public function getRejectionReasonList(){
        $list = config('site.rejectionreason')??[];
        return $list;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }


    public function getPayStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['pay_status'] ?? '');
        $list = $this->getPayStatusList();
        return $list[$value] ?? '';
    }


    public function getDeliveryStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['delivery_status'] ?? '');
        $list = $this->getDeliveryStatusList();
        return $list[$value] ?? '';
    }


    public function getTablewareStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['tableware_status'] ?? '');
        $list = $this->getTablewareStatusList();
        return $list[$value] ?? '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function book()
    {
        return $this->belongsTo('app\admin\model\address\Book', 'address_book_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function details()
    {
        return $this->hasMany('OrderDetail', 'order_id');
    }
}
